<template>
	<view class="page">
		<view class="list-block">
			<view class="list-item" v-for="item in list" :key="item.id" @click="navigate('/pages/violation/detail?id='+item.id)">
				<view class="date-block">
					<view class="day">{{formatDate(item.violationDate, 'day')}}</view>
					<view class="month">{{formatDate(item.violationDate, 'month')}}月</view>
				</view>
				<view class="info-block">
					<view class="title">违章记录</view>
				</view>
				<view class="arrow">
					<text class="iconfont icon-a-gengduo1"></text>
				</view>
			</view>
		</view>
		<view v-if="list.length === 0" class="empty">
			<image src="/static/image/empty.png" class="empty-img"></image>
			<view class="empty-text">暂无违章记录</view>
		</view>
	</view>
</template>

<script>
	import { getViolationListApi } from '@/api/violation.js'
	export default {
		data() {
			return {
				list: []
			}
		},
		methods: {
			getList() {
				getViolationListApi().then(res => {
					this.list = res
				})
			},
			formatDate(dateStr, type) {
				if(!dateStr) return ''
				const date = new Date(dateStr)
				if(type === 'day') {
					return date.getDate()
				} else if(type === 'month') {
					return date.getMonth() + 1
				}
				return ''
			},
			showNotice() {
				uni.showModal({
					title: '温馨提示',
					content: '本页面显示的违章记录仅为人工查询结果，具体信息请在交管12123平台核实为准。',
					showCancel: false,
					confirmText: '我知道了'
				})
			}
		},
		onLoad() {
			this.getList()
			this.showNotice()
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		background-color: #F7F6F9;
		min-height: 100vh;
		position: relative;
		display: flex;
		flex-direction: column;
		.list-block {
			padding: 30rpx;
			.list-item {
				background-color: #fff;
				padding: 30rpx;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				display: flex;
				align-items: center;
				box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
				.date-block {
					width: 120rpx;
					height: 120rpx;
					background: linear-gradient(135deg, #4A8DFF, #3175FF);
					border-radius: 20rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					color: #fff;
					margin-right: 30rpx;
					.day {
						font-size: 48rpx;
						font-weight: bold;
						line-height: 1;
					}
					.month {
						font-size: 24rpx;
						margin-top: 10rpx;
					}
				}
				.info-block {
					flex: 1;
					.title {
						font-size: 32rpx;
						font-weight: bold;
						color: #333;
					}
				}
				.arrow {
					.iconfont {
						font-size: 32rpx;
						color: #999;
					}
				}
			}
		}
		.empty {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			.empty-img {
				width: 300rpx;
				height: 300rpx;
				margin-bottom: 30rpx;
			}
			.empty-text {
				font-size: 28rpx;
				color: #999;
			}
		}
	}
</style> 